import 'package:development_assistant/config/colors.dart';
import 'package:development_assistant/config/font.dart';
import 'package:development_assistant/controller/docker_controller.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

class AddDocker extends StatelessWidget {

  final DockerController dockerController=Get.put(DockerController());

  AddDocker({super.key});
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: _appBar(),
      bottomNavigationBar: _bottomBtn(),
      resizeToAvoidBottomInset: false,
      body: SingleChildScrollView(
        child: Container(
          padding: EdgeInsets.symmetric(vertical: 20.w,horizontal: 20.w),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Text("Docker镜像".tr,style: FontConfig.titleStyle,),
              _dockerField("镜像源".tr,dockerController.dockerFrom),
              _dockerField("镜像名".tr,dockerController.dockerName),
              _dockerField("镜像标签".tr,dockerController.dockerTag),
              _dockerField("镜像ID".tr,dockerController.dockerCid),
              Text("Dockerfile",style: FontConfig.titleStyle,),
              _dockerfile(),
              SizedBox(height: 20.h,)
            ],
          ),
        ),
      ),
    );
  }

  _bottomBtn(){
    return Container(
        width: 350.w,
        height: 35.h,
        margin: EdgeInsets.symmetric(vertical: 10.h),
        child: Center(
          child: ElevatedButton(
            onPressed: (){
              Get.defaultDialog(
                title: "保存Docker镜像".tr,
                middleText: "${'是否保存Docker镜像?'.tr}: ${dockerController.dockerName}",
                confirm: TextButton(
                  style: TextButton.styleFrom(
                      backgroundColor: ColorsConfig().buttonColorOfTheme,
                      foregroundColor: Colors.white,
                      shape: RoundedRectangleBorder(
                          borderRadius: BorderRadius.circular(10)
                      )
                  ),
                  onPressed: (){
                    dockerController.addDocker();
                  },
                  child: Text("确定".tr),
                ),
                cancel:TextButton(
                  style: TextButton.styleFrom(
                      backgroundColor: ColorsConfig().buttonColorOfTheme,
                      foregroundColor: Colors.white,
                      shape: RoundedRectangleBorder(
                          borderRadius: BorderRadius.circular(10)
                      )
                  ),
                  onPressed: (){
                    Get.back();
                  },
                  child: Text("取消".tr),
                ),
              );
            },
            style: ElevatedButton.styleFrom(
                backgroundColor: ColorsConfig().buttonColorOfTheme,
                foregroundColor: Colors.white,
                shape: RoundedRectangleBorder(
                    borderRadius: BorderRadius.circular(20)
                )
            ),
            child:Text("保存Docker镜像".tr,style: TextStyle(fontWeight: FontWeight.bold),),
          ),
        )
    );
  }

  _dockerField(String hintText,RxString dbValue){
    return Container(
      width: 320.w,
      height: 50.h,
      margin: EdgeInsets.symmetric(vertical: 5.h),
      child: Center(
        child: TextField(
          maxLines: 1,
          decoration: InputDecoration(
              hintText:hintText,
              border: OutlineInputBorder(
                borderRadius: BorderRadius.circular(15),
              )
          ),
          onChanged: (e){
            dbValue.value=e;
          },
        ),
      ),
    );
  }

  _dockerfile(){
    return Container(
        height: 200.h,
        margin: EdgeInsets.symmetric(vertical: 10.h),
        decoration: BoxDecoration(
            borderRadius: BorderRadius.circular(10),
            border: Border.all(color:Colors.grey,width: 1)
        ),
        child: TextField(
          maxLines: null,
          decoration: const InputDecoration(
              border: OutlineInputBorder(
                  borderSide: BorderSide.none
              )
          ),
          onChanged: (e){
            dockerController.dockerFile.value=e;
          },
        )
    );
  }

  _appBar(){
    return AppBar(
      title:Text("添加Docker镜像".tr),
      centerTitle: true,
      leading: IconButton(
        onPressed: (){
          Get.offNamed("/Home",arguments: {
            "selectIndex":0
          });
        },
        icon: const Icon(Icons.arrow_back),
      ),
    );
  }
}
